//
//  InitiationPayViewController.m
//  Molian
//
//  Created by xiaocankeji on 16/1/29.
//  Copyright © 2016年 xiaocan. All rights reserved.
//

#import "InitiationPayViewController.h"
#import "InitationSucceedViewController.h"
#import "InitiationFreeViewController.h"
#import "Price.h"
//#import "InitationSucceedViewController.h"
#import "WEBViewController.h"
#import "Order.h"
#import "DataSigner.h"
#import <AlipaySDK/AlipaySDK.h>
#import "WXApi.h"
#import <CommonCrypto/CommonDigest.h>

#import "NetRequest.h"
#import <ifaddrs.h>
#import <arpa/inet.h>
#import "DataMD5.h"
#import "MBProgressHUD.h"



@interface InitiationPayViewController()

//标记当前标签，以索引找到XML文件内容
@property (nonatomic, copy) NSString *currentElement;
//存储解析数据
@property (nonatomic, strong) NSMutableDictionary *xmlDic;
@property (nonatomic, strong) NSString *sn;
@property (nonatomic, strong) NSTimer *timeTimer;
@end

@implementation InitiationPayViewController
{
    UILabel *l2;
    CGFloat payFloat;
    BOOL skipPay;
  //  UILabel *l3;
}
- (NSMutableDictionary *)xmlDic
{
    if (_xmlDic == nil) {
        _xmlDic = [NSMutableDictionary dictionary];
    }
    return _xmlDic;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self checkUserData];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}
- (void)checkUserData
{
    __block MLUser *u = [MLUser currentUser];
    [HUD setOnViewWithTitle:nil animated:YES];
    [u refreshInBackgroundWithBlock:^(AVObject *object, NSError *error) {
        [HUD hideFromViewAnimated:YES];
        if (!error) {
            
            u = (MLUser *)object;
            if (u.isPay == NO) {
                 [MBProgressHUD hideAllHUDsForView:[UIApplication sharedApplication].delegate.window animated:YES];
                
                [_timeTimer invalidate];
                
                if (!skipPay) {
                    skipPay = YES;
                    //免费用户
                    InitiationFreeViewController *init = [[InitiationFreeViewController alloc] init];
                    init.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:init animated:YES];
                }
                
               
                return ;
            }else if (u.isUserInited == 1)  {
                [_timeTimer invalidate];
                
                if (!skipPay) {
                    skipPay = YES;
                [MBProgressHUD hideAllHUDsForView:[UIApplication sharedApplication].delegate.window animated:YES];
                //初始化完成
                InitationSucceedViewController *init = [[InitationSucceedViewController alloc] init];
                init.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:init animated:YES];
                return ;
                }
            }
            
        }else{
           
        }
        
        
    }];
}
- (void)requestPrice
{
    AVQuery *q = [Price query];
    [HUD setOnViewWithTitle:@"" animated:YES];
    
    [q findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        [HUD hideFromViewAnimated:YES];
        if (error == nil) {
            MLUser *u = [MLUser currentUser];
            NSString *pay = @"29.9元";
            payFloat = 29.9;
            NSString *str = @"普通会员";
            for (Price *price in objects) {
               
                if (u.level == price.type) {
                    
                    if(u.gender == MLUserGender_FEMALE){
                        pay = [NSString stringWithFormat:@"%.2f元",price.femalePrice];
                        payFloat = price.femalePrice;
                    }else{
                        pay = [NSString stringWithFormat:@"%.2f元",price.malePrice];
                        payFloat = price.malePrice;
                    }
                    
                    str = price.typeName;
                    break;
                    
                }
            }
             l2.text = [NSString stringWithFormat:@"支付金额: %@",pay];
             //     l3.text = [NSString stringWithFormat:@"会员等级: %@",str];
            
        }else{
            payFloat = 29.9;
        }
        
        
    }];
}



- (void)viewDidLoad
{
    [super viewDidLoad];
     [self.navigationItem setHidesBackButton:YES animated:YES];
    self.navigationItem.rightBarButtonItem = nil;
    self.navigationItem.leftBarButtonItem = nil;
    
    self.title = @"入会审核";
    self.view.backgroundColor =  APPCOLORBACKGROUNDCOLOR(1);
    CGFloat h = DeviceWidth/320*180;
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, DeviceWidth, h)];
   // v.backgroundColor = RGBA(55, 198, 119, 1);
        v.backgroundColor = RGBA(55, 149, 202, 1);
    //    v.backgroundColor = RGBA(244, 152, 68, 1);
    //    v.backgroundColor = RGBA(243, 93, 67, 1);
    [self.view addSubview:v];
    
    UIImageView *i = [[UIImageView alloc] initWithFrame:CGRectMake(DeviceWidth/2 - 50/2, 20, 50, 50)];
    i.image = [UIImage imageNamed:@"check_icon"];
    [v addSubview:i];
    
    
    UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, DeviceWidth - 20, h - 70)];
    l.numberOfLines = 0;
    l.textColor = [UIColor whiteColor];
    l.textAlignment = NSTextAlignmentCenter;
    l.font = kFont(15);
    l.text = @"您的资料通过审核\n完成支付,加入无独团";
    [v addSubview:l];
    
 //   MLUser *u = [MLUser currentUser];
    
//    NSString *pay = @"299元";
//    
//    NSString *str = @"普通会员";
//    if (u.level ==  MLUserLevel_1) {
//        str = @"创始黄金会员";
//        if(u.gender == MLUserGender_FEMALE){
//            pay = @"29元";
//        }else{
//            pay = @"39元";
//        }
//    }else if(u.level == MLUserLevel_2){
//        str = @"创始白金会员";
//        if(u.gender == MLUserGender_FEMALE){
//            pay = @"19元";
//        }else{
//            pay = @"29元";
//        }
//    }else{
//        if(u.gender == MLUserGender_FEMALE){
//            pay = @"39元";
//        }else{
//            pay = @"49元";
//        }
//    }
    
    UIView *v23 = [[UIView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight + h, DeviceWidth, 40)];
    v23.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:v23];
    
    l2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, DeviceWidth, 20)];
    l2.backgroundColor = [UIColor whiteColor];
    l2.textAlignment = NSTextAlignmentCenter;
    l2.textColor = APPCOLOR(1);
    l2.font = kFont(15);
    l2.text = [NSString stringWithFormat:@"支付金额: %@",@""];
    [v23 addSubview:l2];
    
//   l3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, DeviceWidth, 20)];
//    l3.backgroundColor = [UIColor whiteColor];
//    l3.textAlignment = NSTextAlignmentCenter;
//    l3.textColor = APPCOLOR(1);
//    l3.font = kFont(15);
//    
//    
//    l3.text = [NSString stringWithFormat:@"会员等级: %@",str];
//    [v23 addSubview:l3];
    
    
    UIButton *wxBt = [UIButton buttonWithType:UIButtonTypeCustom];
    wxBt.frame = CGRectMake(50, DeviceHeight - 200, DeviceWidth-100, 40);
    wxBt.backgroundColor = RGBA(46, 178, 54, 1);
    wxBt.layer.masksToBounds = YES;
    wxBt.layer.cornerRadius = 5;
    [wxBt setTitle:@"微信支付" forState:UIControlStateNormal];
    // [downBt setImageEdgeInsets:UIEdgeInsetsMake(-2,-18, -2, 0)];
    //[downBt setTitleEdgeInsets:UIEdgeInsetsMake(0, -12, 0, -10)];
    [wxBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [wxBt setTitleColor:RGBA(188, 188, 188, 1) forState:UIControlStateHighlighted];
    wxBt.titleLabel.font = kFont(15);
    [wxBt addTarget:self action:@selector(clickWXBt:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:wxBt];
    
    
    UIButton *downBt = [UIButton buttonWithType:UIButtonTypeCustom];
    downBt.frame = CGRectMake(50, DeviceHeight - 150, DeviceWidth-100, 40);
    downBt.backgroundColor = RGBA(55, 149, 202, 1);
    downBt.layer.masksToBounds = YES;
    downBt.layer.cornerRadius = 5;
    [downBt setTitle:@"支付宝支付" forState:UIControlStateNormal];
    // [downBt setImageEdgeInsets:UIEdgeInsetsMake(-2,-18, -2, 0)];
    //[downBt setTitleEdgeInsets:UIEdgeInsetsMake(0, -12, 0, -10)];
    [downBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [downBt setTitleColor:RGBA(188, 188, 188, 1) forState:UIControlStateHighlighted];
    downBt.titleLabel.font = kFont(15);
    [downBt addTarget:self action:@selector(clickPayBt:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:downBt];
    
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(50, DeviceHeight - 80, DeviceWidth - 50*2, 0.5)];
    line.backgroundColor = RGBA(188, 188, 188, 1);
    [self.view addSubview:line];
    
    UILabel *or = [[UILabel alloc] initWithFrame:CGRectMake(DeviceWidth/2-30, DeviceHeight - 90, 30, 20)];
    or.backgroundColor = APPCOLORBACKGROUNDCOLOR(1);
    or.textColor = RGBA(188, 188, 188, 1);
    or.textAlignment = NSTextAlignmentCenter;
    or.text = @"or";
    or.font = kFont(13);
    [self.view addSubview:or];
    
    
    UILabel *wx = [[UILabel alloc] initWithFrame:CGRectMake(30, DeviceHeight - 70, DeviceWidth - 60, 30)];
    wx.textColor = RGBA(188, 188, 188, 1);
    wx.textAlignment = NSTextAlignmentCenter;
    wx.text = @"您还可以在公众号内完成微信支付";
    wx.font = kFont(14);
    [self.view addSubview:wx];
    
    [self requestPrice];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wxzhifuCG) name:@"wxzhifuCG" object:nil];

}
//微信支付成功
- (void)wxzhifuCG
{
    
    
     [HUD Prompt:@"支付成功,请等待...."];
    //修改用资料
    
    
   // [_timeTimer invalidate];
   // [self modifyUserWx:YES];
    
   
}
//支付宝支付成功
- (void)zfbzhifuCG
{
    [self modifyUserWx:NO];
}
//修改用户资料
- (void)modifyUserWx:(BOOL)wx
{
    
    NSString *remark;
    if (wx) {
        remark = [NSString stringWithFormat:@"会员入会, 微信支付 %.2f元    ios",payFloat];
    }else{
        remark = [NSString stringWithFormat:@"会员入会, 支付宝支付 %.2f元     ios",payFloat];
    }
    
    
    [HUD setOnViewWithTitle:@"" animated:YES];
    MLUser *u = [MLUser currentUser];
    u.isUserInited = 1;
    [u saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        [HUD hideFromViewAnimated:YES];
        if (succeeded) {
            
            [self checkUserData];
            //初始化完成
            InitationSucceedViewController *init = [[InitationSucceedViewController alloc] init];
            init.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:init animated:YES];
            MLConsumeRecord *cR = [MLConsumeRecord object];
            cR.type = MLConsumeRecordType_RECHARGE;
            cR.money = payFloat;
            cR.user = u;
            cR.remark = remark;
            cR.sn = self.sn?self.sn:@"";
            [cR saveEventually];
        }else{
            
            [HUD Prompt:@"修改信息失败,请联系无独团官方人员"];
            
        }
        
    }];
    
    
    
  
    
}

+(NSString *)retBitStringCount:(NSInteger )count
{
    // 此方法随机产生xx位字符串，
    char data[count];
    for (int x=0;x<count;data[x++] = (char)('A' + (arc4random_uniform(26))));
    return [[NSString alloc] initWithBytes:data length:count encoding:NSUTF8StringEncoding];
}

// Get IP Address
- (NSString *)getIPAddress {
    NSString *address = @"error";
    struct ifaddrs *interfaces = NULL;
    struct ifaddrs *temp_addr = NULL;
    int success = 0;
    // retrieve the current interfaces - returns 0 on success
    success = getifaddrs(&interfaces);
    if (success == 0) {
        // Loop through linked list of interfaces
        temp_addr = interfaces;
        while(temp_addr != NULL) {
            if(temp_addr->ifa_addr->sa_family == AF_INET) {
                // Check if interface is en0 which is the wifi connection on the iPhone
                if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
                    // Get NSString from C String
                    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
                }
            }
            temp_addr = temp_addr->ifa_next;
        }
    }
    // Free memory
    freeifaddrs(interfaces);
    return address;}
//微信支付
- (void)clickWXBt:(UIButton *)bt
{
    MLUser *u = [MLUser currentUser];
    
    
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyyMMdd"];
    NSString *date = [formatter stringFromDate:[NSDate date]];
    NSInteger number = arc4random() % 99999999;
    
    //应用id
   
    
    //订单id
    NSString *tradeID = [NSString stringWithFormat:@"%@%ld%@",date,(long)number,u.username];
   
    
    // 商户id
    
    //随机字符串
    
    NSString *nStr = [InitiationPayViewController retBitStringCount:16];
   
    //商品描述
    NSString *body = [NSString stringWithFormat:@"%@ memberPay",u.username];;
    
    //商品详情
    NSString *detail =  [NSString stringWithFormat:@"%.2f元",payFloat]; //详情
    
    //总金额
    NSInteger total_fee =(NSInteger )(payFloat*100);
    
    //通知地址
    NSString *notify_url = kWXNotifyURL;
    
    //交易类型
    NSString *trade_type = @"APP";
   
    //终端IP
    NSString *spbill_create_ip = [self getIPAddress];
    
   
    //签名//detail,@"detail"
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:kWXAppId,@"appid",kPartnerId,@"mch_id",nStr,@"nonce_str",body,@"body",detail,@"detail",tradeID,@"out_trade_no",[NSNumber numberWithInteger:total_fee],@"total_fee",spbill_create_ip,@"spbill_create_ip",notify_url,@"notify_url",trade_type,@"trade_type", nil];
   
    NSString *stringA = [self asciiSortDic:dic];
    NSString *stringSignTemp = [NSString stringWithFormat:@"%@&key=%@",stringA,kWXAppkey];
    NSString *md5Str = [self md5:stringSignTemp];
    NSString *upper = [md5Str uppercaseString];
    
    NSMutableDictionary *last = [NSMutableDictionary dictionaryWithDictionary:dic];
    [last setObject:upper forKey:@"sign"];
    NetRequest *nQ = [[NetRequest alloc] init];

    [nQ SOAPData:kWXPayUrl soapBody:last success:^(id responseObject) {
        
        NSXMLParser *xmlP = [[NSXMLParser alloc] initWithData:responseObject];
        xmlP.delegate = self;
        [xmlP parse];
      //self.xmlDic
        //self.xmlDic
        if([[self.xmlDic objectForKey:@"return_code"] isEqualToString:@"SUCCESS"]){
            
            if([[self.xmlDic objectForKey:@"result_code"] isEqualToString:@"SUCCESS"]){
                
               
                PayReq *request = [[PayReq alloc] init];
                //商户号  ?
                
                
                NSString *wxmch_id = [self.xmlDic objectForKey:@"mch_id"];
                NSString *wxprepay_id = [self.xmlDic objectForKey:@"prepay_id"];
                NSString *wxpackage = @"Sign=WXPay";
                NSString *nonceStr = [self.xmlDic objectForKey:@"nonce_str"];
                request.partnerId = wxmch_id;
                //预支付 交易回话id
                request.prepayId= wxprepay_id;
                self.sn = wxprepay_id;
                request.package = wxpackage;
                request.nonceStr= nonceStr;
                NSDate *adate = [NSDate dateWithTimeIntervalSinceNow:8*60*60];
                NSTimeInterval time = [adate timeIntervalSince1970];
                UInt32 timeS = time;
                //时间戳
                request.timeStamp= timeS;
                
                DataMD5 *md5 = [[DataMD5 alloc] init];
                request.sign=[md5 createMD5SingForPay:kWXAppId partnerid:request.partnerId prepayid:request.prepayId package:request.package noncestr:request.nonceStr timestamp:request.timeStamp];
                
//                NSString   *wxstringA = [NSString stringWithFormat:@"noncestr=%@&package=%@&partnerid=%@&prepayid=%@&timestamp=%@",nonceStr,wxpackage,wxprepay_id,wxmch_id,[NSNumber numberWithInteger:timeS]];
//                
//                NSString *wxstringSignTemp = [NSString stringWithFormat:@"%@&key=%@",wxstringA,kWXAppkey];
//                NSString *wxmd5Str = [self md5:wxstringSignTemp];
//                 NSString *wxupper = [wxmd5Str uppercaseString];
//                request.sign= wxupper;
                [WXApi sendReq:request];
                
               

                //调用微信的,因为支付后可能没有点击返回回调
                [self.timeTimer invalidate];
                 self.timeTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timeTimerAction) userInfo:nil repeats:YES];
                
                
            }else{
                [HUD Prompt:@"请尝试其他支付方式"];
            }
            
            
        }else{
            [HUD Prompt:@"请尝试其他支付方式"];
        }
        
        
    } failure:^(NSError *error) {
         NSLog(@"%@",error.description);
    }];
    
    
   
}
//刷新数据
- (void)timeTimerAction
{
    [self checkUserData];
}
- (void)dealloc
{
    [self.timeTimer invalidate];
}

#pragma mark NSXMLParserDelegate
- (void)parserDidStartDocument:(NSXMLParser *)parser{
    NSLog(@"parserDidStartDocument...");
}
//准备节点
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName attributes:(NSDictionary<NSString *, NSString *> *)attributeDict{
    
   
    self.currentElement = elementName;
}
//获取节点内容
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    
    if ([self.currentElement isEqualToString:@"return_code"]) {
        [self.xmlDic setObject:string forKey:@"return_code"];
        
    }else if ([self.currentElement isEqualToString:@"return_msg"]){
        [self.xmlDic setObject:string forKey:@"return_msg"];
    }else if ([self.currentElement isEqualToString:@"appid"]){
       [self.xmlDic setObject:string forKey:@"appid"];
    }else if ([self.currentElement isEqualToString:@"mch_id"]){
        
       [self.xmlDic setObject:string forKey:@"mch_id"];
    }else if([self.currentElement isEqualToString:@"nonce_str"]){
        [self.xmlDic setObject:string forKey:@"nonce_str"];
    }else if([self.currentElement isEqualToString:@"sign"]){
        [self.xmlDic setObject:string forKey:@"sign"];
    }else if([self.currentElement isEqualToString:@"result_code"]){
        [self.xmlDic setObject:string forKey:@"result_code"];
    }else if([self.currentElement isEqualToString:@"prepay_id"]){
        [self.xmlDic setObject:string forKey:@"prepay_id"];
    }
}

//解析完一个节点
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName{
    
    self.currentElement = nil;
}





//把字典
//ASCII码从小到大排序（字典序）
- (NSString *)asciiSortDic:(NSDictionary *)dic
{
    
    NSArray *arr = [dic allKeys];
    NSArray *sortArr = [arr sortedArrayUsingSelector:@selector(compare:)];
    NSString *str = @"";
    for (NSString *key in sortArr) {
        if (str.length == 0) {
            str = [NSString stringWithFormat:@"%@%@=%@",str,key,[dic objectForKey:key]];
        }else{
            str = [NSString stringWithFormat:@"%@&%@=%@",str,key,[dic objectForKey:key]];
        }
       
    }
    return str;
  
}

//支付宝支付
- (void)clickPayBt:(UIButton *)bt
{
    
//    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"a",@"a",@"c",@"c",@"b",@"b", nil];
//    [self asciiSortDic:dic];
//   
    
    //应用注册scheme,在AlixPayDemo-Info.plist定义URL types
    MLUser *u = [MLUser currentUser];
    //改为客户端
     NSString *appScheme = @"payWDT";
    
    Order *order = [[Order alloc] init];
    order.partner = AlipayPARTNER;
    order.seller = AlipaySELLER;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyyMMdd"];
    NSString *date = [formatter stringFromDate:[NSDate date]];
    NSInteger number = arc4random() % 99999999;
    NSString *tradeID = [NSString stringWithFormat:@"%@%ld%@",date,(long)number,u.username];
    order.tradeNO = tradeID; //订单ID（由商家自行制定）
    self.sn = tradeID;
    order.productName = [NSString stringWithFormat:@"%@ memberPay",u.username];//product.subject; //商品标题
    order.productDescription = [NSString stringWithFormat:@"%.2f元",payFloat]; //商品描述
    order.amount = [NSString stringWithFormat:@"%.2f",payFloat]; //商品价格
    order.notifyURL =  knotifyURL; //回调URL
    order.service = @"mobile.securitypay.pay";
    order.paymentType = @"1";
    order.inputCharset = @"utf-8";
    order.itBPay = @"30m";
    order.showUrl = @"m.alipay.com";
    //将商品信息拼接成字符串
    NSString *orderSpec = [order description];
    NSLog(@"orderSpec = %@",orderSpec);
    //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
    id<DataSigner> signer = CreateRSADataSigner(AlipayRSA_PRIVATE);
    NSString *signedString = [signer signString:orderSpec];
    
    //将签名成功字符串格式化为订单字符串,请严格按照该格式
    NSString *orderString = nil;
    if (signedString != nil) {
        orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
                       orderSpec, signedString, @"RSA"];
        //[HUD setOnViewWithTitle:nil animated:YES];
        [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
          //  [HUD hideFromViewAnimated:YES];
            NSLog(@"reslut = %@",resultDic);
            //如果成功,需要更改判断条件
            if ([[resultDic objectForKey:@"resultStatus"] isEqualToString:@"9000"]) {
                //支付成功
                //[HUD Prompt:@"支付成功"];
                
                
               
                [self zfbzhifuCG];
                
                
                
                
              
                
            }else{
                [HUD Prompt:@"支付失败了"];
            }
            
            
        }];
    }
    
//    MLUser *u = [MLUser currentUser];
//    if (u!=nil&&u.mobilePhoneNumber!=nil) {
//        WEBViewController *web = [[WEBViewController alloc]init];
//        NSString *url = [NSString stringWithFormat:@"http://www.wudutuan.com/member/pay?phone=%@&type=1",u.mobilePhoneNumber];
//        web.WEBURL = url;
//       
//        [self.navigationController pushViewController:web animated:YES];
//    }
//    
    
//    [HUD Prompt:@"需要跳转网页登录,先默认直接支付成功"];
//    MLUser *u = [MLUser currentUser];
//    u.isUserInited = YES;
//    [u saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
//       
//        if (succeeded) {
//            [self checkUserData];
//        }else{
//           [HUD Prompt:@"未知错误"];
//        }
//    }];
    
//    InitationSucceedViewController *init = [[InitationSucceedViewController alloc] init];
//    init.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:init animated:YES];
//    
}
- (NSString *)md5:(NSString *)str
{
    const char *cStr = [str UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, strlen(cStr), result); // This is the md5 call
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            result[0], result[1], result[2], result[3],
            result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11],
            result[12], result[13], result[14], result[15]
            ];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    if ([self isViewLoaded]&&!self.view.window) {
        self.view = nil;
    }
    // Dispose of any resources that can be recreated.
}
@end
